#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#Currently this file is included by two python files here. They are:-
#1. compile_vPath_dissector.py 2. archive_generator.py
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#importing system files....
import os
import errno
import subprocess

#----------------------------------------------------------------------------
#This function makes directory at the path specified if it doesn't
#exist. Otherwise, if its present, then it simply moves forward to the
#next line of code. On successful creation of the directory it returns
#a status code of '0' and if there is an error in creating directory,
#then it returns an error code of '-1000'

def update_dir(path):
    retcode=subprocess.Popen(["git","pull"],shell=False)
    retcode.wait()
    return retcode

def mkdir_p(path):      #This function makes directory at the path
                        #specified. If directory is already there,
                        #then it handles the error.
    try:
        os.mkdir(path)  #making the directory by making system
                        #calls......
    except OSError as err:
        if err.errno==errno.EEXIST:
            pass        #If directory is there, then go
                        #ahead..... Don't stop by displaying
                        #message.......
        else:
            return -1000
    return 0    #returns a status code of 0 which indicates that the
                #function executed successfully...

#--------------------------------------------------------------------------
#This function takes the path of directory whose subdirectories you
#want to list. For example, you want to get the list of all the
#directories present in /home directory, then pass the path as /home
#and it will list all the subdirectories present in the /home
#folder. *****It will not look for subdirectories inside
#subdirectories.******* Returntype: It returns a list containing all
#the subdirectories.....  On error, it exits the program with
#errorcode '1'

def listdir_check(path):      #This function checks whether the path
                              #specified is correct and then lists the
                              #directories in the path......
    try:
        list=os.listdir(path) #This system call lists all the
                              #directories in the path specified.....
        return list
    except OSError as err:    #If error occurs, then perform the
                              #following tasks.....
        return -1001          #So here it returns the errorcode
                              #"-1001" to the program.....
  
#--------------------------------------------------------------------------
